/**
 * Copyright (c) 2014 zhenrongbao.com, Inc. All Rights Reserved
 * @author: jiangshuguang
 * @Date  : 14-10-11
 * @Time  : 下午7:49
 * @brief :
 */
exports.userqueue = function () {
    var $page = $(".widget-userqueue"),
        $queueContainer = $page.find(".queue-container"),
        $queueMoney = $queueContainer.find(".queue-money"),
        $queuePeople = $queueContainer.find(".queue-people"),
        $dataItems = $queueContainer.find(".queue-data-bar .data-item");

    var selfMoneyTpl = '' +
            '<div class="tip self-tip">' +
            '<div>我的资金(<span class="day"></span>天)</div>' +
            '<div class="tip-value"></div>' +
            '</div>',
        otherMoneyTpl =  '' +
            '<div class="tip other-tip">' +
            '<div>预估排队<span class="day"></span>天</div>' +
            '<div class="tip-value"></div>' +
            '</div>',
        selfPeopleTpl = '<div class="tip self-tip">我的位置</di>',
        otherPeopleTpl = '<div class="tip other-tip"></div>';

    $dataItems.on("mouseover",function(e){
        var offsetLeft = $(this).attr("data-center"),
            dataValue = $(this).attr("data-value"),
            type = $(this).attr("data-type"),
            waitDay = $(this).attr("data-wait-day"),
            left = Math.ceil((offsetLeft/100)*700 -100),
            $tip;

        if(type == "other-money"){
            $queueMoney.find(".tip").remove();
            $tip = $(otherMoneyTpl).appendTo($queueMoney.find(".queue-data-bar")).css({
                left:left
            });
            $tip.find(".tip-value").text("￥"+dataValue);
            $tip.find(".day").text(waitDay);
        }else if(type == "self-money"){
            $queueMoney.find(".tip").remove();
            $tip = $(selfMoneyTpl).appendTo($queueMoney.find(".queue-data-bar")).css({
                left:left
            });
            $tip.find(".tip-value").text("￥"+dataValue);
            $tip.find(".day").text(waitDay);
        }else if(type == "other-people"){
            $queuePeople.find(".tip").remove();
            $tip =  $(otherPeopleTpl).appendTo($queuePeople.find(".queue-data-bar")).css({
                left:left
            }).text(dataValue+"人");
        }else if(type == "self-people"){
            $queuePeople.find(".tip").remove();
            $tip =  $(selfPeopleTpl).appendTo($queuePeople.find(".queue-data-bar")).css({
                left:left
            });
        }
        $tip.on("click",function(){
            $(this).remove();
        });
    }).on("mouseout",function(){
            var type = $(this).attr("data-type");
            if(type == "other-money" || type == "self-money"){
                $queueMoney.find(".tip").remove();
            }else if(type == "other-people" || type == "self-people"){
                $queuePeople.find(".tip").remove();
            }
        });

    $dataItems.each(function(k,v){
        var type = $(this).attr("data-type");
        if(type == "self-money" || type == "self-people"){
            $(this).trigger("mouseover");
        }
    });
};